import { childrenProps } from '@/components/ProForm/interface';
import { PublicInterface } from '@/interface/public';

export interface InterfaceStatusProp {
  label: string;
  value: number | string;
  type?: 'option';
  tag?: PublicInterface.PublicType['buttonType'];
}

/**
 * @param {String} names 需要获取数据字典的名称 (多个以逗号隔开)
 * @description 获取数据字典内容 children 中只，并装换为下拉框所需要格式
 */
export const getDictionaryListByCodes = async (pidCode: string, value?: string, isRole?: boolean) => {
  const data = await dataDictionaryFindByCode({ pidCode, isRole: isRole });
  const backData: Record<string, childrenProps[]> = {};
  Object.keys(data).forEach(key => {
    backData[key] = arrTransitionSelectData(data[key], 'label', value || 'value');
  });
  return backData;
};

/**
 * @description: 根据状态获取对应数据内容
 * @return {*}
 */
export const getStatusName = (arr: InterfaceStatusProp[], status: string | number) => {
  return arr.find(item => item.value + '' === status + '')?.label;
};

/**
 * @description：启用 / 禁用
 */
export const statusEnableOrDisabled: InterfaceStatusProp[] = [
  { label: 'enable', value: 1, tag: 'success' },
  { label: 'disabled', value: 0, tag: 'danger' }
];

/**
 * @description：提交 / 保存
 */
export const statusSaveOrSubmit: InterfaceStatusProp[] = [
  { label: 'save', value: 0, tag: 'warning' },
  { label: 'submit', value: 1, tag: 'success' }
];

/**
 * 是 | 否
 */
export const statusYesOrNo: InterfaceStatusProp[] = [
  { label: '是', value: 1, type: 'option' },
  { label: '否', value: 0, type: 'option' }
];

/**
 * 操作类型
 */
export const statusOperateType: InterfaceStatusProp[] = [
  { label: '按钮', value: 'button', type: 'option' },
  { label: '查询', value: 'search', type: 'option' },
  { label: '菜单', value: 'menu', type: 'option' },
  { label: '公共菜单', value: 'menu_public', type: 'option' }
];

/**
 * 数据字典可见类型
 */
export const statusDictVisibleType: InterfaceStatusProp[] = [
  { label: '所有用户可见', value: 0, type: 'option' },
  { label: '对应角色可见', value: 1, type: 'option' }
];
